<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>测试</title>
		<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
	</head>
	<body>
		<div class="bd">
                <div class="upload_label">上传图片(最多可上传9张)</div>
                <div class="cDiv" id="listView"></div>

                <div class="cDiv clearfix" id="inputDiv">
                    <div class="weui_uploader_input_wrp">
                        ![](/img/mobile/icon_add.png)
                        <input class="weui_uploader_input" id="input" type="file" accept="image/*" multiple="multiple" />
                    </div>
                </div>
            </div>
	</body>
	<script src="../js/jq331.min.js"></script>
	<script>
		$(document).on("click",".btn_add",function () {
        $('#input').trigger('click')
    });

    $(document).on("change","#input",function () {
        var input = $(this)[0]; // input 控件
        imagesChanged(input);
    });
  
/**
 * 添加图片回调
 */
function imagesChanged(input) {
    var files = input.files;

    // 假设 "listView" 是将要展示图片的 div
    var listView = $("#listView");

    for (var i = 0; i < files.length; i++) { //新添加的图片
        var file = files[i];
        imgFiles.push(file);

        // Make sure `file.name` matches our extensions criteria
        if ( !/\.(jpe?g|png|gif)$/i.test(file.name) ) {
            continue;
        }
        var options = {
            orientation: true,
            maxWidth: 640,
        }

        loadImage(
            file,
            function (img) {
                var base = img.toDataURL("image/jpeg");
                var imgRow = getImageRow(base);
                imgData.push(base);
                // add_doc(base);
                listView.append(imgRow);
            },
            options // Options
        );
        //最多张数
        if (imgFiles.length >= imgCountMax) {
            $("#inputDiv").hide();
            break;
        }
    }
}

// 插入一行图片
function getImageRow(imgSrc) {
    // 向 listView 添加一行 row
    var imgRow =
        '<div class="cell_img" >' +
        '![](/img/mobile/icon_del.png)'+
        '![](' + imgSrc + ')</img>' +
        '</div>';
    return imgRow;
}

	</script>
</html>
